from collections.abc import Iterable, Mapping
from typing import Any, Literal, TypeVar

AnyItem = TypeVar('AnyItem')


def parse_item_weight_pairs(
    items: Mapping[AnyItem, float] | Iterable[tuple[AnyItem, float]] | Iterable[AnyItem], *,
    default: Literal['raise', 'equal', 'len'] = 'equal',
    typ: type[AnyItem] | Any = object,
) -> tuple[tuple[AnyItem, ...], tuple[float, ...]]:
    if isinstance(items, Mapping):
        # noinspection PyTypeChecker
        return zip(*items.items())
    if isinstance(items, Iterable):
        items = tuple(items)
        if all(isinstance(item, typ) for item in items):
            if default == 'equal':
                return items, tuple(1.0 for _ in items)
            if default == 'len':
                return items, tuple(len(items) for _ in items)
            raise TypeError(f"Expected Mapping or Iterable of tuples, got {items}")
        if all(all([
            isinstance(item, tuple), len(item) == 2,
            isinstance(item[0], typ), isinstance(item[1], float)]
        ) for item in items):
            # noinspection PyTypeChecker
            return zip(*items)
    raise TypeError(f"items must be Mapping or Iterable, got {items}")
